<template>
  <div style="margin-top: 15px">
    <el-pagination
      :current-page="currentPage"
      :page-sizes="pageSizes"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>
<script>
export default {
  data() {
    return {
      currentPage: 1,
      pageSize: 20,
    };
  },
  props: {
    pageSizes: {
      type: Array,
      default: () => [10, 20, 50, 100],
    },
    total: {
      type: Number,
      required: true,
    },
    pageNum: {
      type: Number,
      default: 1,
    },
    pageSizeNum: {
      type: Number,
      default: 20,
    },
  },
  watch: {
    pageNum: {
      handler(val) {
        this.currentPage = val;
      },
    },
    pageSizeNum: {
      handler(val) {
        this.pageSize = val;
      },
    },
  },
  methods: {
    handleSizeChange(val) {
      this.pageSize = val;
      // 向父组件传递分页信息
      this.$emit("pagination", { pageNum: 1, pageSize: val });
    },
    handleCurrentChange(val) {
      this.$emit("pagination", { pageNum: val, pageSize: this.pageSize });
    },
  },
};
</script>
